package n11;

/**
 * @author 苏文广
 * @since 2021/10/8
 */
public class ViolentSolution {


    // 暴力破解, 超时, 双层for循环
    public static void main(String[] args) {
        Solution solution = new Solution();
        int i = solution.maxArea(new int[]{1, 8, 6, 2, 5, 4, 8, 3, 7});
        System.out.println(i);
    }

    static class Solution {
        public int maxArea(int[] height) {
            if (height == null || height.length < 2) {
                return 0;
            }

            int max = 0;

            // 双指针
            // left
            int left = 0;
            // right
            int right = height.length - 1;

            for (int i = right; i > left; i--) {

                for (int j = left; j < right; j++) {
                    int x = i - j;
                    if (x <= 0) {
                        continue;
                    }

                    int y = Math.min(height[i], height[j]);
                    int temp = x * y;
                    max = Math.max(temp, max);
                }
            }


            return max;
        }
    }
}

